package rm.metrology.shared;

public class Validator {

	public static boolean isNullOrEmpty(String str) {
		return (str == null) || (str.trim().length() == 0);
	}
	
	public static boolean hasMinLen(String str, int minLen) {
		if (str == null) return true; // can be checked by isNullOrEmpty
		return (str.length() >= minLen);
	}
	
	public static boolean hasMaxLen(String str, int maxLen) {
		if (str == null) return true; // can be checked by isNullOrEmpty
		return (str.length() <= maxLen);
	}
	
	public static boolean hasLen(String str, int len) {
		if (str == null) return true; // can be checked by isNullOrEmpty
		return (str.length() == len);
	}
	
	public static boolean isEmail(String str) {
		if (str == null) return true; // can be checked by isNullOrEmpty
		return str.matches("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$");
	}
	
	public static boolean isPhone(String str) {
		if (str == null) return true; // can be checked by isNullOrEmpty
		return str.matches("^[379]{1}[0-9]{6}$");
	}
	
	public static boolean isNIC(String str) {
		if (str == null) return true; // can be checked by isNullOrEmpty
		return str.matches("^[ABab]{1}[0-9]{6}$");
	}
	
}
